package com.itheima.controller;

import com.itheima.model.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.*;

/**
 * todo
 *
 * @author Chengfei
 * @date 2020/8/23 20:36
 */

@Controller
@RequestMapping("/thymeleaf")
public class ThmeleafController {
    /**
     * 访问/test/hello    跳转demo1页面
     */
    @RequestMapping("/hello")
    public String hello(Model model,String id){
        model.addAttribute("hello","hello welcome");
        System.out.println("接受的值:"+id);

        //集合数据
        List<User> users = new ArrayList<>();
        users.add(new User(1,"张三","深圳"));
        users.add(new User(2,"李四","北京"));
        users.add(new User(3,"王五","武汉"));
        model.addAttribute("users",users);

        //Map定义
        Map<String,Object> dataMap = new HashMap<>();
        dataMap.put("No","123");
        dataMap.put("address","深圳");
        model.addAttribute("dataMap",dataMap);

        //存储一个数组
        String[] names = {"张三","李四","王五"};
        model.addAttribute("names",names);

        //后台日期
        model.addAttribute("now",new Date());

        //if条件
        model.addAttribute("age",22);


        return "demo";
    }


}
